import 'package:flutter/material.dart';
import 'package:imitating_tiktok/pages/add_pages/add_page.dart';
import 'package:imitating_tiktok/pages/base_pages/base_navigation_bar.dart';
import 'package:imitating_tiktok/pages/home_pages/home_page.dart';
import 'package:imitating_tiktok/pages/message_pages/message_page.dart';
import 'package:imitating_tiktok/pages/profile_pages/profile_page.dart';
import 'package:imitating_tiktok/pages/search_pages/search_page.dart';

class BasePage extends StatefulWidget {
  const BasePage({Key? key}) : super(key: key);

  @override
  _BasePageState createState() => _BasePageState();
}

class _BasePageState extends State<BasePage> {
  int _selectedIndex = 0;
  static const List<Widget> _layoutPageList = [
    HomePage(),
    SearchPage(),
    AddPage(),
    MessagePage(),
    ProfilePage()
  ];

  // MARK: - 底部选择按钮元素，重绘界面
  void _doSelectedAction(int index) {
    setState(() {
      _selectedIndex = index;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: _layoutPageList[_selectedIndex],
      ),
      bottomNavigationBar: BaseNavigationBar(
        selectedIndex: _selectedIndex,
        doSelectedAction: _doSelectedAction,
      ),
    );
  }
}
